import request from '@/utils/request'

// 获取用户订单列表
export function getUserOrders(params) {
  return request({
    url: '/material-orders/user/orders',
    method: 'get',
    params
  })
}

// 获取订单详情
export function getOrderDetails(orderNumber) {
  return request({
    url: `/material-orders/${orderNumber}`,
    method: 'get'
  })
}

// 创建新订单
export function createOrder(data) {
  return request({
    url: '/material-orders',
    method: 'post',
    data
  })
}

// 生成下载令牌
export function generateDownloadToken(orderNumber) {
  return request({
    url: `/material-orders/${orderNumber}/download-token`,
    method: 'post'
  })
}

// 验证下载令牌
export function verifyDownloadToken(orderNumber, token) {
  return request({
    url: `/material-orders/${orderNumber}/verify-token/${token}`,
    method: 'get'
  })
}

// 管理员：获取所有订单
export function getAllOrders(params) {
  return request({
    url: '/material-orders/admin/all',
    method: 'get',
    params
  })
}

// 管理员：更新订单状态
export function updateOrderStatus(orderNumber, status) {
  return request({
    url: `/material-orders/${orderNumber}/status`,
    method: 'put',
    data: { status }
  })
}